<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="客户编号" prop="customerId">
                        <el-input v-model="dataForm.customerId" placeholder="客户编号"></el-input>
                </el-form-item>
                <el-form-item label="客户名称" prop="customerName">
                        <el-input v-model="dataForm.customerName" placeholder="客户名称"></el-input>
                </el-form-item>
                <el-form-item label="服务案例编号" prop="serviceCaseId">
                        <el-input v-model="dataForm.serviceCaseId" placeholder="服务案例编号"></el-input>
                </el-form-item>
                <el-form-item label="服务案例名称" prop="serviceCaseName">
                        <el-input v-model="dataForm.serviceCaseName" placeholder="服务案例名称"></el-input>
                </el-form-item>
                <el-form-item label="服务开始日期" prop="serviceStartDate">
                        <el-date-picker
                                v-model="dataForm.serviceStartDate"
                                type="datetime"
                                placeholder="服务开始日期">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="服务结束日期" prop="serviceEndDate">
                        <el-date-picker
                                v-model="dataForm.serviceEndDate"
                                type="datetime"
                                placeholder="服务结束日期">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="服务状态" prop="serviceStatus">
                        <el-input v-model="dataForm.serviceStatus" placeholder="服务状态"></el-input>
                </el-form-item>
                <el-form-item label="服务质量评分" prop="evaluationScore">
                        <el-input v-model="dataForm.evaluationScore" placeholder="服务质量评分"></el-input>
                </el-form-item>
                <el-form-item label="评估日期" prop="evaluationDate">
                        <el-date-picker
                                v-model="dataForm.evaluationDate"
                                type="datetime"
                                placeholder="评估日期">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="客户反馈" prop="customerFeedback">
                        <el-input v-model="dataForm.customerFeedback" placeholder="客户反馈"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            customerId: null,
            customerName: null,
            serviceCaseId: null,
            serviceCaseName: null,
            serviceStartDate: null,
            serviceEndDate: null,
            serviceStatus: null,
            evaluationScore: null,
            evaluationDate: null,
            customerFeedback: null
          },
          dataRule: {
            id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
            ],
            customerId: [
                        { required: true, message: '客户编号不能为空', trigger: 'blur' }
            ],
            customerName: [
                        { required: true, message: '客户名称不能为空', trigger: 'blur' }
            ],
            serviceCaseId: [
                        { required: true, message: '服务案例编号不能为空', trigger: 'blur' }
            ],
            serviceCaseName: [
                        { required: true, message: '服务案例名称不能为空', trigger: 'blur' }
            ],
            serviceStartDate: [
                        { required: true, message: '服务开始日期不能为空', trigger: 'blur' }
            ],
            serviceEndDate: [
                        { required: true, message: '服务结束日期不能为空', trigger: 'blur' }
            ],
            serviceStatus: [
                        { required: true, message: '服务状态不能为空', trigger: 'blur' }
            ],
            evaluationScore: [
                        { required: true, message: '服务质量评分不能为空', trigger: 'blur' }
            ],
            evaluationDate: [
                        { required: true, message: '评估日期不能为空', trigger: 'blur' }
            ],
            customerFeedback: [
                        { required: true, message: '客户反馈不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.id = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.id = id || 0
            if (this.dataForm.id) {
              this.$http({
                url: this.$http.adornUrl(`/app/service_quality_evaluation/info/${this.dataForm.id}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appservicequalityevaluation
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/service_quality_evaluation/${!this.dataForm.id ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>